package com.wish.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wish.dao.GroupDao;
import com.wish.dao.PermissionDao;
import com.wish.dao.UserDao;
import com.wish.model.Group;
import com.wish.model.Permission;
import com.wish.model.User;

@Service
public class UserService
{
	@Resource
	private UserDao userDao;

	@Resource
	private GroupDao groupDao;

	@Resource
	private PermissionDao permissionDao;

	@Transactional(readOnly = true)
	public User getUserByUserName(String userName)
	{
		User user = userDao.getUserByUserName(userName);
		user.getPermissions().size();
		return user;
	}

	@Transactional(readOnly = true)
	public List<Permission> getPermissionList()
	{
		return permissionDao.getList();
	}

	@Transactional(readOnly = true)
	public List<User> getUserList(long groupID)
	{
		return userDao.getList(groupID);
	}

	@Transactional(readOnly = false)
	public void addUser(User user)
	{
		userDao.insert(user);
	}

	@Transactional(readOnly = false)
	public void removeUser(long id)
	{
		userDao.delete(id);
	}

	@Transactional(readOnly = true)
	public List<Group> getGroupList()
	{
		return groupDao.getList();
	}

	@Transactional(readOnly = false)
	public void addGroup(Group group)
	{
		groupDao.insert(group);
	}
}
